//
//  MyTableViewCell.swift
//  swiftTableView
//
//  Created by 梁佳佳 on 2016/10/21.
//  Copyright © 2016年 梁佳佳. All rights reserved.
//

import UIKit

class MyTableViewCell: UITableViewCell {
    
    //MARK: - 初始化
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = UIColor.darkGray
        self.createUI()//创建UI
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //MARK: - 自定义方法
    func createUI() -> Void {
        self.addSubview(myImageView)
        self.addSubview(myTitleLabel)
        self.addSubview(myDecLabel)
    }
    func createDataWithModel(tableModel:TableModel) -> Void {
        self.myImageView.image = UIImage(named: tableModel.imageName as String)
        self.myDecLabel.text = tableModel.myDescription as String
        self.myTitleLabel.text = tableModel.name as String
    }
    //MARK: - 懒加载
    //图片
    lazy var myImageView: UIImageView = {
        var tempImageView:UIImageView = UIImageView(frame: CGRect(x: 10, y: 10, width: 20, height: 20))
        tempImageView.image = UIImage(named: "1")
        return tempImageView
    }()
    //标题
    lazy var myTitleLabel: UILabel = {
        var tempLabel:UILabel = UILabel(frame: CGRect(x: 40, y: 10, width: self.frame.maxX - 20 - 40, height: 15))
        tempLabel.font = UIFont.systemFont(ofSize: 20)
        tempLabel.textColor = UIColor.black
        return tempLabel
    }()
    //描述
    lazy var myDecLabel: UILabel = {
        var tempLabel:UILabel = UILabel(frame: CGRect(x: 40, y: 40, width: self.frame.maxX - 20 - 40, height: 15))
        tempLabel.font = UIFont.systemFont(ofSize: 14)
        tempLabel.textColor = UIColor.red
        return tempLabel
    }()
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
